<template>
  <div class="container">
    <div class="admin">
      <el-row :gutter="20">
        <el-col
          :span="6"
          :xs="24"
          :sm="12"
          :md="6"
          v-for="item in performance"
          :key="item.title"
        >
          <el-card>
            <div slot="header" class="clearfix card-header">
              <span>{{ item.title }}</span>
              <el-tooltip
                class="item"
                effect="dark"
                content="查看详情"
                placement="top"
                :enterable="false"
              >
                <i
                  class="iconfont icon-prompt"
                  @click="onDetail"
                  style="float: right; padding: 3px 0; cursor: pointer"
                ></i>
              </el-tooltip>
            </div>
            <div :class="`card-body ${item.fontColor}`">
              <i :class="'iconfont ' + item.icon"></i>
              {{ item.sum }}
            </div>
            <div class="card-footer">
              <span>
                增长趋势 {{ item.trend }}
                <i class="el-icon-top" style="color: red"></i>
              </span>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <el-row style="margin-top: 20px">
        <el-col :span="24">
          <el-card>
            <div id="main" style="width: 100%; height: 350px"></div>
          </el-card>
        </el-col>
      </el-row>
      <!-- <div>
        <el-card>
          <div slot="header" class="clearfix card-header">
            <span>活跃排行榜</span>
            <el-tooltip
              class="item"
              effect="dark"
              content="查看详情"
              placement="top"
              :enterable="false"
            >
              <i
                class="iconfont icon-prompt"
                @click="onDetail"
                style="float: right; padding: 3px 0; cursor: pointer"
              ></i>
            </el-tooltip>
          </div>
          <ol class="users">
            <li v-for="(item, index) in users" :key="index">
              <el-badge
                :value="index + 1"
                class="item"
                :type="sortColor(index)"
              >
              </el-badge>
              <el-avatar size="small" :src="item.imageSrc"></el-avatar>
              <div class="name">
                {{ item.userName }}
              </div>
            </li>
          </ol>
        </el-card>
      </div> -->
    </div>
  </div>
</template>

<script>
import performance from "./welcomeData";

export default {
  name: "Admin",
  data() {
    return {
      performance,
      users: null,
      user: null,
    };
  },
  created() {
    let userStr = window.sessionStorage.getItem("user");
    this.user = JSON.parse(userStr);
    console.log(this.user);
  },
  mounted() {
    this.initEcharts();
  },
  methods: {
    initEcharts() {
      // 基于准备好的dom，初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById("main"));

      // 指定图表的配置项和数据
      let option = {
        xAxis: {
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: "line",
            smooth: true,
          },
        ],
      };

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    },
    onDetail() {
      console.log("detail");
    },
    sortColor(index) {
      switch (index) {
        case 0:
          return "danger";
        case 1:
          return "success";
        case 2:
          return "warning";
        default:
          return "primary";
      }
    },
    getLocalTime() {
      return /[\u4E00-\u9FA5]+/.exec(new Date().toLocaleString()).shift();
    },
  },
};
</script>

<style lang="less" scoped>
.admin {
  .el-card {
    font-size: 0.75rem;
    .users {
      font-size: 1rem;
      li {
        margin-bottom: 20px;
        display: flex;
        align-items: center;
        .el-avatar {
          margin-left: 10px;
        }
        .name {
          margin-left: 10px;
        }
      }
    }
  }

  .card-body {
    font-weight: 500;
    font-size: 32px;
    margin: 10px 0;
    i {
      font-size: 32px;
    }
    &.red {
      color: red;
      i {
        color: red;
      }
    }
    &.green {
      color: green;
      i {
        color: green;
      }
    }
  }
  .card-footer {
    border-top: 1px solid #ddd;
    margin-top: 20px;
    padding-top: 10px;
    font-size: 0.75rem;
  }
  #main {
    width: 100%;
  }
}
.news {
  li {
    overflow: hidden;
    white-space: nowrap;
    line-height: 3rem;
    padding: 0 1rem;
    margin-bottom: 1em;
    cursor: pointer;
    text-overflow: ellipsis;
    border-bottom: 1px solid #f1f2f4;
    border-radius: 6px;
    &:hover {
      background-color: whitesmoke;
      color: #000;
    }
  }
}
</style>
